<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-select
            v-model="dataForm.status"
            placeholder="请选择状态"
            clearable
          >
            <el-option label="停用" value="0"> </el-option>
            <el-option label="正常" value="1"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.name"
            placeholder="请输入房型名称"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item>
          <el-input
            v-model="dataForm.rateCode"
            placeholder="请输入房型编码"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item>
          <el-input
            v-model="dataForm.shortName"
            placeholder="请输入房型简称"
            clearable
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('hotel:houseinfo:save')"
            type="primary"
            @click="addOrUpdateHandle()"
            >{{ $t("add") }}</el-button
          >
        </el-form-item>
        <!-- <el-form-item>
          <el-button
            type="primary"
            @click="copyRooom()"
            >复制房间</el-button
          >
        </el-form-item> -->
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
        :height="he"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="房型名称"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <!-- <el-table-column
          prop="shortName"
          label="房型简称"
          header-align="center"
          align="center"
        ></el-table-column> -->
        <el-table-column
          prop="isPutaway"
          label="上下架"
          header-align="center"
          align="center"
          min-width="140px"
        >
          <template slot-scope="scope">
            <el-switch
              :disabled="
                $hasPermission('hotel:houseinfo:updPutaway') ? false : true
              "
              @change="(val) => changeStatus(scope.row.id, val)"
              :value="scope.row.isPutaway"
              :active-value="1"
              :inactive-value="0"
              active-color="#13ce66"
              inactive-color="#ddd"
              active-text=""
              inactive-text=""
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column
          prop="roomCount"
          label="房间数量"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="房间号"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <div
              class="box"
              :style="{ 'max-height': scope.row.maxH + 'px', overflow: hidden }"
            >
              <p
                v-for="(i, index) in scope.row.roomFloor"
                :key="index"
                style="margin: 0; line-height: 30px"
              >
                {{ i.floor }}F-{{ i.roomNumber }}
              </p>
            </div>
            <span
              @click="scope.row.maxH = scope.row.roomFloor.length * 30"
              class="showOrHiden zz"
              v-if="scope.row.roomFloor.length > 3 && scope.row.maxH == 90"
              >展开</span
            >
            <span
              @click="scope.row.maxH = 90"
              class="showOrHiden zz"
              v-if="
                scope.row.roomFloor.length > 3 &&
                scope.row.maxH == scope.row.roomFloor.length * 30
              "
              >收起</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="payTyp"
          label="携程房型映射"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-link
              v-if="scope.row.payType"
              type="success"
              :underline="false"
              @click="concatLink(scope.row.homestayId,scope.row.id,scope.row.name,scope.row.payType)"
              >已关联</el-link
            >
            <el-link
              v-else
              type="info"
              :underline="false"
              @click="concatLink(scope.row.homestayId,scope.row.id,scope.row.name,scope.row.payType)"
              >未关联</el-link
            >
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="美团房型ID"
          header-align="center"
          align="center"
        >
        <template slot-scope="scope">
            <el-input
              style="width: 120px; transform: scale(0.8)"
              v-model="scope.row.mtRoomId"
            ></el-input>
            <i
              class="el-icon-check"
              v-if="$hasPermission('hotel:houseinfo:updateMtProduct')"
              @click="confirmVal(scope.row)"
            ></i>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="230"
        >
          <template slot-scope="scope">
            <!-- <el-button
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
              >基础信息</el-button
            > -->
            <el-button
              v-if="$hasPermission('hotel:houseinfo:oneClickCopy')"
              type="text"
              size="small"
              @click="copyRooom(scope.row.id)"
              >复制房间</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('hotel:houseinfo:update')"
              @click="addOrUpdateHandle2(scope.row.id)"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('hotel:houseinfo:delete')"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
      <!-- 批量定价 -->
      <show-info
        v-if="addOrUpdateVisible2"
        ref="addOrUpdate2"
        @refreshDataList="getDataList"
      ></show-info>
      <!-- 展示信息 -->
      <!-- 携程关联 -->
      <concat-link
        v-if="concatLinkVisible"
        ref="concatLink"
        @refreshDataList="getDataList"
      ></concat-link>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./roomShape-add-or-update";
import showInfo from "./roomShape-show-info";
import concatLink from "./roomShape-concatLink";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/hotel/house/base/page",
        getDataListIsPage: true,
        deleteURL: "/hotel/house/base/deleteOne",
        deleteIsBatch: false,
      },
      he: "auto",
      concatLinkVisible: false,
      addOrUpdateVisible2: false,
      dataForm: {
        name: "",
        rateCode: "",
        shortName: "",
        status: "",
      },
      currentId: "",
      ids: [],
      addOrUpdateVisible3: false,
    };
  },
  components: {
    AddOrUpdate,
    showInfo,
    concatLink,
  },
  watch: {
    dataList(newval, oldval) {
      if (
        newval != oldval &&
        newval.length > 0 &&
        !newval[0].hasOwnProperty("maxH")
      ) {
        this.dataList = newval.map((item) => {
          return { ...item, maxH: 90 };
        });
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 270px)";
        }, 500);
      }
    },
  },
  methods: {
    confirmVal(row) {
      this.$http
        .put("/hotel/house/base/updateMtProduct", {
          id: row.id,
          mtRoomId: parseFloat(row.mtRoomId),
        })
        .then((res) => {
          if (res.data.code !== 0) {
            return this.$message.error(res.data.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {},
          });
        });
    },
    //复制房间专用
    copyRooom(id) {
      this.$confirm(`确定复制该房型 `, this.$t("prompt.title"), {
        confirmButtonText: this.$t("confirm"),
        cancelButtonText: this.$t("cancel"),
        type: "warning",
      })
        .then(() => {
          this.$http
            .post("/hotel/house/base/houseCopy", {
              houseBaseId: id,
            })
            .then((res) => {
              if (res.data.code !== 0) {
                return this.$message.error(res.data.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  this.getDataList();
                },
              });
            });
        })
        .catch(() => {});
    },
    changeStatus(id, status) {
      this.$confirm(
        `确定${status ? "上架" : "下架"}？`,
        this.$t("prompt.title"),
        {
          confirmButtonText: this.$t("confirm"),
          cancelButtonText: this.$t("cancel"),
          type: "warning",
        }
      )
        .then(() => {
          this.$http
            .post("/hotel/house/base/updPutawayState", {
              id: id,
              isPutaway: status,
            })
            .then((res) => {
              if (res.data.code !== 0) {
                return this.$message.error(res.data.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  this.getDataList();
                },
              });
            });
        })
        .catch(() => {
          console.log(1);
        });
    },
    toHref(id, roomNumbers) {
      //this.currentId=id;
      this.$router.push({
        path: "priceSetList",
        query: { id: id, roomNumbers: roomNumbers },
      });
    },
    addOrUpdateHandle2(id) {
      this.addOrUpdateVisible2 = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate2.dataForm.id = id;
        this.$refs.addOrUpdate2.init();
      });
    },
    concatLink(homestayId,id,name,payType) {
      this.$router.push({name:'roomShape-concatLink',query:{ms_hotel_id:homestayId,ms_room_name:name,ms_room_id:id,payType:payType}})
      // this.concatLinkVisible = true;
      // this.$nextTick(() => {
      //   this.$refs.concatLink.dataForm.ms_hotel_id = id;
      //   this.$refs.concatLink.init();
      // });
    },
  },
};
</script>
<style scoped lang="scss">
.zz {
  display: block;
  height: 22px;
  line-height: 22px;
  position: relative;
  z-index: 1;
  color: blue;
  background-color: #fff;
  cursor: pointer;
  // &:hover
  // {
  //   background-color: #f5f7fa;
  // }
}
/deep/.el-table__body tr.hover-row > td {
  .zz {
    background-color: #f5f7fa;
  }
}
</style>
